/*
 * Copyright (c) 2009, Jan Pastor. All Rights Reserved.
 */

package sk.jp.jitag.model;

import com.db4o.config.annotations.Indexed;

import sk.jp.jitag.dao.db4o.Column;
import sk.jp.jitag.dao.db4o.Unique;
import sk.jp.jitag.dao.db4o.BaseEntity;

/**
 * Tag (keyword).
 */
public class Tag extends BaseEntity {

    public static final int NAME_MAX_LEN = 256;

    private static final Column _NAME = new Column("name");
    private static final Column _PARENT_TAG = new Column("parentTag");

    //----------------------------------------------------------------------

    /**
     * Name (label) of tag.
     * <p>unique, indexed, notnull, maxlen:{@link #NAME_MAX_LEN}, read-only.
     */
    @Indexed
    @Unique
    private String name = null;

    /**
     * Parent tag in hierarchy.
     * <p>
     */
    private Tag parentTag = null;

    //----------------------------------------------------------------------

    public Tag(String name) {
        checkNotNullNotEmpty(_NAME, name);
        checkMaxLen(_NAME, name, NAME_MAX_LEN);

        this.name = name;
    }

    //----------------------------------------------------------------------

    public String getName() {
        return name;
    }

    public Tag getParentTag() {
        return parentTag;
    }

    public Tag setParentTag(Tag parentTag) {
        this.parentTag = parentTag;
        return this;
    }

    @Override
    public String toString() {
        return "Tag{" +
               "name='" + name + '\'' +
               ", parentTag.name='" + (parentTag != null ? parentTag.getName() : "null") + '\'' +
               '}';
    }
}
